package com.situ.day10;

import org.junit.Test;

import java.util.*;

public class CollectionDemo {

    /**
     * List: ArrayList   有序可重复
     * Set: HashSet      无序不可重复
     * Map: HashMap      key-value 键值对结构
     */
    @Test
    public void test1() {
        int[] array1 = new int[3];
        String[] array2 = new String[3];
        //数组最大的问题：长度固定，操作下标
        //ArrayList<String> list = new ArrayList<>();
        List<String> list = new ArrayList<>();
        list.add("java");
        list.add("ui");
        list.add("h5");
        list.add("h5");
        list.add("aa");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        //foreach
        for (String str : list) {
            System.out.println(str);
        }

    }

    @Test
    public void test2() {
        //HashSet<String> set = new HashSet<>();
        Set<String> set = new HashSet<>();
        set.add("java");
        set.add("ui");
        set.add("h5");
        set.add("h5");
        set.add("aa");
        for (String str : set) {
            System.out.println(str);
        }
    }

    @Test
    public void test5() {
        //key-value
        HashMap<String, String> map = new HashMap<>();
        map.put("cn", "zhongguo");
        map.put("us", "meiguo");
        map.put("uk", "yingguo");

        String value1 = map.get("cn");
        System.out.println(value1);
        String value2 = map.get("us");
        System.out.println(value2);

        Set<Map.Entry<String, String>> set = map.entrySet();
        for (Map.Entry<String, String> entry : set) {
            System.out.println(entry.getKey() + "--" + entry.getValue());
        }


    }

    @Test
    public void test6() {
        List<Integer> list = new ArrayList<>();
        list.add(12);
        list.add(5);
        list.add(8);
        Integer max = Collections.max(list);
        System.out.println(max);

        Collections.reverse(list);

        for (Integer integer : list) {
            System.out.println(integer);
        }
    }

}
